<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title>Sending GET/POST request with dhtmlxAjax</title>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<meta name="featured" content="yes"><meta name="title" content="Samples" />
		<meta name="keywords" content="" />
		<meta name="description" content="" />
		<link rel="icon" href="../common/favicon.ico" type="image/x-icon" />
		<link rel="shortcut icon" href="../common/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="../common/css/style.css" type="text/css" media="screen" />

	</head>
	<body>
        <div class="header">
            <a class="logo" href="http://www.dhtmlx.com" title="DHTMLX homepage"></a>
            <div class="tittle-dhtmlx">DHTMLX Docs & Samples Explorer</div>
            <div class="search-field">
                <form action="http://docs.dhtmlx.com/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit">Search</button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>
            </div>
            <div class="buttons">
                <a class="doc_inact" href="../../../docsExplorer/index.html" title="DHTMLX Documentation homepage"></a>
                <a class="sample"></a>
            </div>
        </div>
        <div class="content">
            <div class="navigation-div">
                <a href="../../../docsExplorer/samples.html" class="navigation"><img src="../common/icons/file.gif" alt="" >All components</a>
                <div class="arrow"></div>
                <a href="../index.html" class="navigation"><img height="22" src="../common/icons/ajax.gif" alt="" >dhtmlxAjax</a>
                <div class="arrow"></div>
                <a href="./index.html" class="navigation"><img src="../common/icons/none.gif" alt="" >Samples of Usage</a>
            </div>
            <div style="display:block;">
                <h3>Sending GET/POST request with dhtmlxAjax</h3>
            </div>
            <div class="navigation-div">
                <a href="#code" class="navigation view-source"><img src="../common/icons/source.gif" alt="" >View page source</a>
            </div>
            <script  src="../../codebase/dhtmlxcommon.js"></script>
	<script>
		function outputResponse(loader){
			if(loader.xmlDoc.responseXML!=null)
				alert("We Got Response\n\n"+loader.doSerialization())
			else
				alert("Response contains no XML")
		}
		function sendRequestGet(){
			if(!document.getElementById('sync').checked){
				dhtmlxAjax.get("php/process.php?"+encodeURI(document.getElementById('params').value),outputResponse);
				alert("Request Sent");
			}else{
				var loader = dhtmlxAjax.getSync("php/process.php?"+encodeURI(document.getElementById('params').value));
				alert("Request Sent");
				outputResponse(loader)
			}
		}
		function sendRequestPost(){
			if(!document.getElementById('sync').checked){
				dhtmlxAjax.post("php/process.php",encodeURI(document.getElementById('params').value),outputResponse);
				alert("Request Sent");
			}else{
				var loader = dhtmlxAjax.postSync("php/process.php",encodeURI(document.getElementById('params').value));
				alert("Request Sent");
				outputResponse(loader)
			}
				
		}
	</script>


	
	<p>Add your own parameters and submit AJAX Request*. Output will contain xml with all parameters server got.</p>
	
	<h3>Parameters: <input type="Text" value="param1=value&param2=value" id="params" style="width:300px;">&nbsp;<button onclick="sendRequestGet()">GET</button>&nbsp;<button onclick="sendRequestPost()">POST</button>

<input type="checkbox" id="sync"> Use Synchronous Mode</h3>

* - this sample requires PHP to run correctly and show what it has to show. Unfortunately there is no possiblity to process submitted parameters and output results wthout server side programming. But syntax which was demonstrated in this sample suits for ststic XML files also.
			
			
         </div>
    <div class="source">
        <div class="teg">Source</div>
        <div class="code" id="code">
		<div class="hl-main"><pre><span class="hl-brackets">&lt;</span><span class="hl-reserved">script</span><span class="hl-code">  </span><span class="hl-var">src</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">../../codebase/dhtmlxcommon.js</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">&gt;</span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">script</span><span class="hl-brackets">&gt;</span><span class="hl-code">
</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">script</span><span class="hl-brackets">&gt;</span><span class="hl-code"><div class="hl-main"><pre><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">outputResponse</span><span class="hl-brackets">(</span><span class="hl-identifier">loader</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">loader</span><span class="hl-code">.</span><span class="hl-identifier">xmlDoc</span><span class="hl-code">.</span><span class="hl-identifier">responseXML</span><span class="hl-code"> != </span><span class="hl-reserved">null</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">alert</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">We Got Response</span><span class="hl-special">\n</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">loader</span><span class="hl-code">.</span><span class="hl-identifier">doSerialization</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-reserved">else</span><span class="hl-code">;
    </span><span class="hl-identifier">alert</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Response contains no XML</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">sendRequestGet</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code">!</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">sync</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">checked</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">dhtmlxAjax</span><span class="hl-code">.</span><span class="hl-identifier">get</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">php/process.php?</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">encodeURI</span><span class="hl-brackets">(</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">params</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">value</span><span class="hl-brackets">)</span><span class="hl-code">, </span><span class="hl-identifier">outputResponse</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">alert</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Request Sent</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">var</span><span class="hl-code"> </span><span class="hl-identifier">loader</span><span class="hl-code"> = </span><span class="hl-identifier">dhtmlxAjax</span><span class="hl-code">.</span><span class="hl-identifier">getSync</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">php/process.php?</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">encodeURI</span><span class="hl-brackets">(</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">params</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">value</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">alert</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Request Sent</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">outputResponse</span><span class="hl-brackets">(</span><span class="hl-identifier">loader</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">sendRequestPost</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code">!</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">sync</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">checked</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">dhtmlxAjax</span><span class="hl-code">.</span><span class="hl-identifier">post</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">php/process.php</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">encodeURI</span><span class="hl-brackets">(</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">params</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">value</span><span class="hl-brackets">)</span><span class="hl-code">, </span><span class="hl-identifier">outputResponse</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">alert</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Request Sent</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">var</span><span class="hl-code"> </span><span class="hl-identifier">loader</span><span class="hl-code"> = </span><span class="hl-identifier">dhtmlxAjax</span><span class="hl-code">.</span><span class="hl-identifier">postSync</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">php/process.php</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">encodeURI</span><span class="hl-brackets">(</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">params</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">value</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">alert</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Request Sent</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">outputResponse</span><span class="hl-brackets">(</span><span class="hl-identifier">loader</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></pre></div></span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">script</span><span class="hl-brackets">&gt;</span><span class="hl-code">
 
 
</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">h3</span><span class="hl-brackets">&gt;</span><span class="hl-code">Parameters: </span><span class="hl-brackets">&lt;</span><span class="hl-reserved">input</span><span class="hl-code"> </span><span class="hl-var">type</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">Text</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">value</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">param1=value&amp;param2=value</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">id</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">params</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">style</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">width:300px;</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">&gt;</span><span class="hl-special">&amp;nbsp;</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">button</span><span class="hl-code"> </span><span class="hl-var">onclick</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">sendRequestGet()</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">&gt;</span><span class="hl-code">GET</span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">button</span><span class="hl-brackets">&gt;</span><span class="hl-special">&amp;nbsp;</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">button</span><span class="hl-code"> </span><span class="hl-var">onclick</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">sendRequestPost()</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">&gt;</span><span class="hl-code">POST</span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">button</span><span class="hl-brackets">&gt;</span><span class="hl-code">
</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">input</span><span class="hl-code"> </span><span class="hl-var">type</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">checkbox</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">id</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">sync</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">&gt;</span><span class="hl-code"> Use Synchronous Mode</span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">h3</span><span class="hl-brackets">&gt;</span><span class="hl-code">
* - this sample requires PHP to run correctly and show what it has to show. Unfortunately there is no possiblity to process submitted parameters and output results wthout server side programming. But syntax which was demonstrated in this sample suits for ststic XML files also.</span></pre></div>
        </div>
    <div class="footer">
        <div class="footer-logo"></div>
        <div class="copyright">Copyright &copy; 1998-2011 DHTMLX LTD.<br />All rights reserved.</div>
    </div>
	</body>
</html>